/**
 * Created with IntelliJ IDEA.
 * User: Kotone
 * Date: 2016/4/18
 * Time: 13:27
 * To change this template use File | Settings | File Templates.
 */

var houseSourceId = request('houseSourceId');

function getBuilding() {
    $('#appointmentHref').attr('href', 'appointment.html?houseSourceId=' + houseSourceId);
    $.ajax({
        method: 'GET',
        url: ctx + "/houseSource/getHouseSource",
        data: {
            houseSourceId: houseSourceId
        },
        async: false,
        success: function (response) {
            var houseSource = response.data;
            $('#name').html(houseSource.buildingName);
            var images = houseSource.images.split(',');
            for (var i in images) {
                var image = images[i];
                var id = "image" + i;
                $('#images').append('<div class="swiper-slide"><img width="100%" id="' + id + '"  data-id="' + i + '"></div>');
                $.ajax({
                    url: ctx + "/photos/getPhoto",
                    data: {
                        key: image,
                        waterMark: true
                    },
                    imageId: id,
                    method: "get",
                    async: false,
                    success: function (response) {
                        //alert(response.responseText)
                        var url = response;
                        document.getElementById(this.imageId).src = url + "|imageView2/1/w/" + window.innerWidth + "/h/212";
                    },
                    failure: function (response, opts) {

                    }
                });
            }
            $('#contentArea').html('<div class="h-xs-6"> ' +
                '<span class="price"><span>' + houseSource.totalPrice + '</span></span>' +
                '</div>' +
                '<div class="h-xs-6">' +
                '</div>' +
                '<div class="h-xs-6">' +
                '<span>面积：' + houseSource.area + '</span>' +
                '</div>' +
                '<div class="h-xs-6">' +
                '<span>工 letters ：' + houseSource.workplace + '</span>' +
                '</div>' +
                '<div class="h-xs-6">' +
                '<span>单价：' + houseSource.unitPrice + '</span>' +
                '</div>' +
                '<div class="h-xs-6">' +
                '<span>交付标准：' + houseSource.standardStr + '</span>' +
                '</div>' +
                '<div class="clearfix"></div>');
            $.ajax({
                method: 'GET',
                url: ctx + "/building/getBuilding",
                data: {
                    buildingId: houseSource.buildingId
                },
                async: false,
                success: function (response) {
                    var building = response.data;
                    //var mapParams='?province='+building.addressResponse.province+
                    //              '&city='+building.addressResponse.city+
                    //              '&district='+building.addressResponse.district+
                    //              '&centerAddress='+building.addressResponse.address+
                    //              '&buildingName='+building.name+
                    //              '&radius=0';

                    var mapParams = '?lat=' + building.addressResponse.lat +
                        '&lng=' + building.addressResponse.lng +
                        '&buildingName=' + building.name +
                        '&radius=0';

                    var tags = building.tags.split(',');
                    var tagHtml = '';
                    for (var i in tags) {
                        tagHtml += '<span class="tip">' + tags[i] + '</span>';
                    }
                    $('#contentAddress').html
                    ('<li class="top2">' +
                        '<div class="lt-area">' +
                        '<div class="h-xs-6">' +
                        '<span>城市：' + building.addressResponse.city + '</span>' +
                        '</div>' +
                        '<div class="h-xs-6">' +
                        '<span>区域：' + building.addressResponse.district + '</span>' +
                        '</div>' +
                        '<div class="h-xs-6">' +
                        '<span>地址：' + building.addressResponse.address + '</span>' +
                        '</div>' +
                        '<div class="clearfix"></div>' +
                        '<p>' + tagHtml + '</p>' +
                        '</div>' +
                        '<div class="rt-area area2">' +
                        '<a href="map.html' + mapParams + '" class="bicon bicon-map">地图</a>' +
                        '</div>' +
                        '</li>');
                    var floorsNum = "";
                    var elevatorNum = "";
                    var parkingPositionNum = "";
                    if (null != building.floorsNum) {
                        floorsNum = building.floorsNum;
                    }
                    if (null != building.elevatorNum) {
                        elevatorNum = building.elevatorNum;
                    }
                    if (null != building.parkingPositionNum) {
                        parkingPositionNum = building.parkingPositionNum;
                    }
                    $('#contentDetail').append
                    ('<li>' +
                        '<div class="h-xs-6"><span class="c-gray">物业等级：</span> ' + building.level + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">物业费：</span> ' + building.maintenanceFee + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">层数：</span> ' + floorsNum + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">电梯数量：</span>' + elevatorNum + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">净高：</span>' + building.layerHeight + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">得房率：</span> ' + building.usablePercentage + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">车 letters 数：</span> ' + parkingPositionNum + '</div>' +
                        '<div class="h-xs-6"><span class="c-gray">建筑面积：</span> ' + building.totalArea + '</div>' +
                        '</li>');

                }
            });
        }
    });
}

getBuilding();
//$(document).ready(function () {
//    getBuilding();
//});